import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-29
 * Time: 22:27
 */
public class test1 {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode cur1 = list1;
        ListNode cur2 = list2;
        ListNode newHead = new ListNode(-1);
        ListNode prev = newHead;
        while(cur1!=null && cur2!=null){
            if(cur1.val<=cur2.val){
                prev.next = cur1;
                cur1 = cur1.next;
            }else{
                prev.next = cur2;
                cur2 = cur2.next;
            }
            prev = prev.next;
        }
        prev.next = cur1==null?cur2:cur1;
        return newHead.next;
    }

    class ListNode{
        int val;
        ListNode next;


        public ListNode(int val){
            this.val = val;
        }
    }
}
